<?php
/**
 * Created by PhpStorm.
 * User: sunshubo
 * Date: 2017/9/20
 * Time: 11:06
 */

class TaskInfo extends CI_Model
{
    /**
     * @param $data
     * @return string
     */
    function add_task($data)
    {
        $id = $data['name'];
        $last_date = date("Y.m.d");
        $courseId = $data['course'];
        $err_type = $data['error_type'];
        $err_rate = $data['error_rate'];
        $comp_rate = $data['completion_rate'];
        $err_detail = $data['late_mark'];
        $tutorId = $data['tutor'];
        $sql = /** @lang text */
            "INSERT INTO ws_task(id,last_date,courseId,err_type,err_rate,comp_rate,err_detail,tutorId) VALUE($id,'$last_date',$courseId,'$err_type',$err_rate,$comp_rate,'$err_detail',$tutorId)";
//        $this->db->trans_start();
        $query = $this->db->query($sql);
//        $this->db->trans_complete();
        $error = $this->db->error();
        if ($query) {
            return json_encode(array('result' => SUCCESS, 'msg' => $this->config->item('mysql_msg')[$error['code']]));
        }
        return json_encode(array('result' => ERROR, 'msg' => $this->config->item('mysql_msg')[$error['code']], 'code' => $error['code']));
    }
}